home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / storebmp / storebmp.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-01-11  |  6.3 KB  |  211 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Store and Display Pictures"
  5.    ClientHeight    =   6165
  6.    ClientLeft      =   2475
  7.    ClientTop       =   2070
  8.    ClientWidth     =   5055
  9.    Height          =   6570
  10.    Icon            =   STOREBMP.FRX:0000
  11.    Left            =   2415
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   6165
  14.    ScaleWidth      =   5055
  15.    Top             =   1725
  16.    Width           =   5175
  17.    Begin CommandButton Command3 
  18.       Caption         =   "Bye"
  19.       Height          =   1095
  20.       Left            =   4440
  21.       TabIndex        =   4
  22.       Top             =   4920
  23.       Width           =   495
  24.    End
  25.    Begin TextBox Text1 
  26.       DataField       =   "PictureName"
  27.       DataSource      =   "Data1"
  28.       Height          =   285
  29.       Left            =   120
  30.       TabIndex        =   2
  31.       Top             =   5640
  32.       Width           =   2415
  33.    End
  34.    Begin CommandButton Command2 
  35.       Caption         =   "Delete Picture"
  36.       Height          =   495
  37.       Left            =   2760
  38.       TabIndex        =   1
  39.       Top             =   5520
  40.       Width           =   1575
  41.    End
  42.    Begin CommandButton Command1 
  43.       Caption         =   "Load Picture"
  44.       Height          =   495
  45.       Left            =   2760
  46.       TabIndex        =   0
  47.       Top             =   4920
  48.       Width           =   1575
  49.    End
  50.    Begin Data Data1 
  51.       Caption         =   "View Pictures"
  52.       Connect         =   ""
  53.       DatabaseName    =   "STOREBMP.MDB"
  54.       Exclusive       =   0   'False
  55.       Height          =   270
  56.       Left            =   120
  57.       Options         =   0
  58.       ReadOnly        =   0   'False
  59.       RecordSource    =   "PictureTable"
  60.       Top             =   5040
  61.       Width           =   2415
  62.    End
  63.    Begin CommonDialog OpenDialog 
  64.       CancelError     =   -1  'True
  65.       DialogTitle     =   "Select Bitmap or Icon"
  66.       Filter          =   "Pictures(*.bmp;*.ico)|*.bmp;*.ico"
  67.       InitDir         =   "c:\windows"
  68.       Left            =   120
  69.       Top             =   120
  70.    End
  71.    Begin Label Label1 
  72.       BackColor       =   &H00C0C0C0&
  73.       Caption         =   "File Name"
  74.       Height          =   255
  75.       Left            =   120
  76.       TabIndex        =   3
  77.       Top             =   5400
  78.       Width           =   1815
  79.    End
  80.    Begin Image Image1 
  81.       BorderStyle     =   1  'Fixed Single
  82.       Height          =   4695
  83.       Left            =   120
  84.       Stretch         =   -1  'True
  85.       Top             =   120
  86.       Width           =   4815
  87.    End
  88. Option Explicit
  89. Dim PictureDB As Database
  90. Dim PictureTB As Dynaset
  91. Dim CurrentDir As String
  92. Sub CenterForm (FormToCenter As Form)
  93.     FormToCenter.Top = (Screen.Height - FormToCenter.Height) / 2
  94.     FormToCenter.Left = (Screen.Width - FormToCenter.Width) / 2
  95. End Sub
  96. Sub Command1_Click ()
  97.     Dim FileToLoad As String
  98.     Dim ChunkSize As Integer
  99.     Dim TotalSize As Long
  100.     Dim NumberOfChunks As Long
  101.     Dim Remainder As Integer
  102.     Dim CurChunk As String
  103.     Dim HoldName As String
  104.     Dim SearchCriteria As String
  105.     Dim i As Integer
  106.     Screen.MousePointer = 11
  107.     On Error GoTo ErrorHandler1
  108.     OpenDialog.Action = 1
  109.     FileToLoad = OpenDialog.Filetitle
  110.     PictureTB.AddNew
  111.     PictureTB("PictureName") = FileToLoad
  112.     'Load picture data
  113.     ChunkSize = 12000
  114.     Open OpenDialog.Filename For Binary As #1
  115.     TotalSize = LOF(1)
  116.     NumberOfChunks = TotalSize \ ChunkSize
  117.     Remainder = TotalSize Mod ChunkSize
  118.     For i = 0 To NumberOfChunks
  119.         If i = NumberOfChunks Then
  120.             CurChunk = String$(Remainder, " ")
  121.             Get #1, , CurChunk
  122.             PictureTB("PictureData").AppendChunk (CurChunk)
  123.             Exit For
  124.         End If
  125.         CurChunk = String$(ChunkSize, " ")
  126.         Get #1, , CurChunk
  127.         PictureTB("PictureData").AppendChunk (CurChunk)
  128.     Next i
  129.     PictureTB.Update
  130.     Close #1
  131.     HoldName = FileToLoad
  132.     Data1.Refresh
  133.     SearchCriteria = "PictureName = '" + HoldName + "'"
  134.     Data1.Recordset.FindFirst SearchCriteria
  135.     If Data1.Recordset.NoMatch Then
  136.         Stop
  137.     End If
  138.     ChDir CurrentDir
  139.     Screen.MousePointer = 0
  140. ErrorHandler1:
  141. If Err = 32755 Then
  142.     ChDir CurrentDir
  143.     Screen.MousePointer = 0
  144.     Exit Sub
  145. End If
  146. End Sub
  147. Sub Command2_Click ()
  148.     Screen.MousePointer = 11
  149.     If Data1.Recordset.RecordCount = 0 Then
  150.         image1.Picture = LoadPicture("")
  151.         Screen.MousePointer = 0
  152.         Exit Sub
  153.     End If
  154.     Data1.Recordset.Delete
  155.     Data1.Refresh
  156.     If Data1.Recordset.RecordCount = 0 Then
  157.         image1.Picture = LoadPicture("")
  158.     End If
  159.     Screen.MousePointer = 0
  160. End Sub
  161. Sub Command3_Click ()
  162.     End
  163. End Sub
  164. Sub Data1_Reposition ()
  165.     Dim Offset As Long
  166.     Dim ChunkSize As Integer
  167.     Dim TotalSize As Long
  168.     Dim NumberOfChunks As Long
  169.     Dim Remainder As Integer
  170.     Dim CurChunk As String
  171.     Dim i As Integer
  172.     Dim x As String
  173.     Screen.MousePointer = 11
  174.     ChDir CurrentDir
  175.     If PictureTB.RecordCount = 0 Or Data1.Recordset.RecordCount = 0 Then
  176.         Screen.MousePointer = 0
  177.         Exit Sub
  178.     End If
  179.     'Load picture data
  180.     ChunkSize = 12000
  181.     Open Data1.Recordset("PictureName") For Binary As #2
  182.     TotalSize = Data1.Recordset("PictureData").FieldSize()
  183.     NumberOfChunks = TotalSize \ ChunkSize
  184.     Remainder = TotalSize Mod ChunkSize
  185.     Offset = 0
  186.     For i = 0 To NumberOfChunks
  187.         If i = NumberOfChunks Then
  188.             CurChunk = Data1.Recordset("PictureData").GetChunk(Offset, Remainder)
  189.             Put #2, , CurChunk
  190.             Exit For
  191.         End If
  192.         CurChunk = Data1.Recordset("PictureData").GetChunk(Offset, ChunkSize)
  193.         Put #2, , CurChunk
  194.         Offset = Offset + ChunkSize
  195.     Next i
  196.     Close #2
  197.     image1.Picture = LoadPicture(Data1.Recordset("PictureName"))
  198.     x = CurDir$
  199.     Kill Data1.Recordset("PictureName")
  200.     Screen.MousePointer = 0
  201. End Sub
  202. Sub Form_Load ()
  203.     Set PictureDB = OpenDatabase("Storebmp.mdb")
  204.     Set PictureTB = PictureDB.CreateDynaset("PictureTable")
  205.     CurrentDir = CurDir$
  206.     If Right(CurrentDir, 1) = "\" Then
  207.         CurrentDir = Mid(CurrentDir, 1, Len(CurrentDir) - 1)
  208.     End If
  209.     Call CenterForm(Me)
  210. End Sub
  211.